package com.forum.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.forum.model.entity.PostAuditLog;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 帖子审核日志Mapper接口
 */
@Mapper
public interface PostAuditLogMapper extends BaseMapper<PostAuditLog> {
    
    /**
     * 获取帖子的审核日志
     * @param postId 帖子ID
     * @return 审核日志列表
     */
    @Select("SELECT l.*, u.username as auditor_name " +
            "FROM post_audit_log l " +
            "LEFT JOIN user u ON l.auditor_id = u.id " +
            "WHERE l.post_id = #{postId} " +
            "ORDER BY l.created_at DESC")
    List<PostAuditLog> selectByPostId(@Param("postId") Long postId);
    
    /**
     * 获取最近的审核日志
     * @param limit 限制数量
     * @return 最近的审核日志
     */
    @Select("SELECT l.*, u.username as auditor_name, p.title as post_title " +
            "FROM post_audit_log l " +
            "LEFT JOIN user u ON l.auditor_id = u.id " +
            "LEFT JOIN post p ON l.post_id = p.id " +
            "ORDER BY l.created_at DESC " +
            "LIMIT #{limit}")
    List<PostAuditLog> selectRecent(@Param("limit") Integer limit);
} 